package com.yhq.basic.jvm.classload.others;

/**
 * @author hqyin
 * @date 2023/3/1 4:13 下午
 */
public class TestDynamicLoad {
    static {
        System.out.println("*******load TestDynamicLoad*******");
    }

    public static void main(String[] args) throws NoSuchFieldException {
        //什么时候类会被加载
        new A();
        //System.out.println(B.a);;
        Class<B> bClass = B.class;
        System.out.println(bClass.getField("a"));
    }

}

class A {
    static {
        System.out.println("*******load A*******");
    }

    public A() {
        System.out.println("*******initial A*******");
    }
}

class B {
    public static int a = 1;

    static {
        System.out.println("*******load B*******");
    }

    public B() {
        System.out.println("*******initial B*******");
    }
}
